package com.lupus.business.inspector;

import java.util.*;
import javax.servlet.http.*;
import com.lupus.business.Inspectable;
import com.lupus.common.CommonFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public final class ExportInspector implements Inspectable {

	public boolean preInspect(Map<String, Object> requestMap, Map<String, Object> responseMap, HttpServletRequest request, HttpServletResponse response){
		return true;
	}

	public boolean sufInspect(Map<String, Object> requestMap, Map<String, Object> responseMap, HttpServletRequest request, HttpServletResponse response){
		HSSFWorkbook workbook = CommonFactory.exportExcel((List<Map>)responseMap.get("titleValues"),(List<Map>)responseMap.get("dataValues"));
		response.setHeader("Content-Type", "application/ms-excel");
		response.setHeader("Content-disposition","attachment;filename=" + requestMap.get("fileName"));
		try{
			workbook.write(response.getOutputStream());
		}catch(Exception e){
			throw new RuntimeException(e);
		}
		return false;
	}
}
